#if defined myenter_inc
 #endscript
#endif
#define myenter_inc

#include <a_samp>


#if !defined MAX_ENTRIES
 #define MAX_ENTRIES 20
#endif

#if !defined FORW_DIST
 #define FORW_DIST 2.5
#endif

#define LINKS_AMOUNT 2

//#define ALLOW_ANIM

	/*
	Float:e_x1,
	Float:e_y1,
	Float:e_z1,
	Float:e_a1,
	Float:e_x2,
	Float:e_y2,
	Float:e_z2,
	Float:e_a2,
	e_int1,
	e_int2


enum entstruct
{
	e_pickupid[LINKS_AMOUNT],
	Float:e_pos[LINKS_AMOUNT][4],
	e_int[LINKS_AMOUNT]
};
*/
#if defined ALLOW_ANIM
forward SetPlayerToEntrace(playerid, i, j);
#endif

static e_pickupid[MAX_ENTRIES][LINKS_AMOUNT],
	Float:e_pos[MAX_ENTRIES][LINKS_AMOUNT][4],
	e_int[MAX_ENTRIES][LINKS_AMOUNT];



//static entpoints[MAX_ENTRIES][entstruct];
static ent_count = 0;

stock AddEntrace(Float:x1, Float:y1, Float:z1, Float:a1, Float:x2, Float:y2, Float:z2, Float:a2, int1 = 0, int2 = 0, worldid = 0)
{
	if(ent_count >= MAX_ENTRIES)
		return(-1);
	// store data
	/*
	entpoints[ent_count][e_x1] = x1;
	entpoints[ent_count][e_y1] = y1;
	entpoints[ent_count][e_z1] = z1 + 0.3;
	entpoints[ent_count][e_a1] = a1;
	entpoints[ent_count][e_x2] = x2;
	entpoints[ent_count][e_y2] = y2;
	entpoints[ent_count][e_z2] = z2 + 0.3;
	entpoints[ent_count][e_a2] = a2;*/
	e_pos[ent_count][0][0] = x1;
	e_pos[ent_count][0][1] = y1;
	e_pos[ent_count][0][2] = z1 + 0.25;
	e_pos[ent_count][0][3] = a1;
	e_pos[ent_count][1][0] = x2;
	e_pos[ent_count][1][1] = y2;
	e_pos[ent_count][1][2] = z2 + 0.25;
	e_pos[ent_count][1][3] = a2;

	e_int[ent_count][0] = int1;
	e_int[ent_count][1] = int2;

	e_pickupid[ent_count][0] =
		CreatePickup(1318, 23, x1, y1, z1, worldid); // create entrace pickup
	e_pickupid[ent_count][1] =
		CreatePickup(1318, 23, x2, y2, z2, worldid); // create entrace pickup
	return(ent_count++);
}

stock PopEntrace()
{
	if(ent_count <= 0) return -1;
	else --ent_count;
	/*
	DestroyPickup(entpoints[ent_count][e_pickupid[0]]);
	DestroyPickup(entpoints[ent_count][e_pickupid[1]]);
	entpoints[ent_count][e_x1] = 0.0;
	entpoints[ent_count][e_y1] = 0.0;
	entpoints[ent_count][e_z1] = 0.0;
	entpoints[ent_count][e_a1] = 0.0;
	entpoints[ent_count][e_x2] = 0.0;
	entpoints[ent_count][e_y2] = 0.0;
	entpoints[ent_count][e_z2] = 0.0;
	entpoints[ent_count][e_a2] = 0.0;
	entpoints[ent_count][e_int1] = 0;
	entpoints[ent_count][e_int2] = 0;
	entpoints[ent_count][e_pickupid1] = 0;
	entpoints[ent_count][e_pickupid2] = 0;
	*/
	for(new i=0; i < LINKS_AMOUNT; i++)
	{
		for(new j=0; j < 4; j++)
			e_pos[ent_count][i][j] = 0.0;
		e_int[ent_count][i] = 0;
		DestroyPickup(e_pickupid[ent_count][i]);
		e_pickupid[ent_count][i] = 0;
	}
	return ent_count;
}

stock ExitEntrace(playerid)
{
	new pint = GetPlayerInterior(playerid);
	if(!pint) return false;
	for(new i = 0; i < ent_count; i++) // compare
	{
		for(new j = 0; j < LINKS_AMOUNT; j++)
		{
			if(e_int[i][j] == pint && IsPlayerInRangeOfPoint(playerid, 150.0, e_pos[i][j][0], e_pos[i][j][1], e_pos[i][j][2]))
			{
				SetPlayerPos(playerid, e_pos[i][j][0], e_pos[i][j][1], e_pos[i][j][2]);
			}
		}
	}
	return true;
}

ent_ParsePickUp(playerid, pickupid)
{
	for(new i = 0; i < ent_count; i++) // compare with pickups DB
	{
		for(new j = 0; j < LINKS_AMOUNT; j++)
		{
			if(pickupid == e_pickupid[i][j])
			{
				#if defined ALLOW_ANIM
				SetPlayerFacingAngle(playerid, e_pos[i][j][3] + 180.0);
				ApplyAnimation(playerid, "PED", "WALK_civi", 4.0, 1, 1, 1, 1, 1);
				SetTimerEx("SetPlayerToEntrace", 2000, false, "idd", playerid, i, GetReversiveLinkIndex(j));
				TogglePlayerControllable(playerid, false);
				#else
				j = GetReversiveLinkIndex(j);
				new Float:x = e_pos[i][j][0] + (FORW_DIST * floatsin(-e_pos[i][j][3], degrees));
				new Float:y = e_pos[i][j][1] + (FORW_DIST * floatcos(-e_pos[i][j][3], degrees));
				ApplyAnimation(playerid, "PED", "WALK_civi", 4.0, 0, 0, 0, 0, 1);
				TogglePlayerControllable(playerid, true);
				//ClearAnimations(playerid);
				SetPlayerPos(playerid, x, y, e_pos[i][j][2]);
				SetPlayerFacingAngle(playerid, e_pos[i][j][3]);
				SetPlayerInterior(playerid, e_int[i][j]);
				SetCameraBehindPlayer(playerid);
				#endif
				return true;
			}
		}
	}
	return false;
}

#if defined ALLOW_ANIM
public SetPlayerToEntrace(playerid, i, j)
{
	new Float:x = e_pos[i][j][0] + (FORW_DIST * floatsin(-e_pos[i][j][3], degrees));
	new Float:y = e_pos[i][j][1] + (FORW_DIST * floatcos(-e_pos[i][j][3], degrees));
	ApplyAnimation(playerid, "PED", "WALK_civi", 4.0, 0, 0, 0, 0, 1);
	TogglePlayerControllable(playerid, true);
	//ClearAnimations(playerid);
	SetPlayerPos(playerid, x, y, e_pos[i][j][2]);
	SetPlayerFacingAngle(playerid, e_pos[i][j][3]);
	SetPlayerInterior(playerid, e_int[i][j]);
	SetCameraBehindPlayer(playerid);
}
#endif

static GetReversiveLinkIndex(index)
{
	++index;
	if(index >= LINKS_AMOUNT)
		index = 0;
	return index;
}




